<?php include 'inc/teacher_head.php';?>



<div class="layui-container">

    <div class="layui-row layui-form layui-form-pane" id='div_bjkc'>
            <!-- 插入选择班级、课程的组件 -->
            <?php [$showTitle, $showClass, $showTask]  = [ 1, 1, 1]; ?>
            <?php include 'inc/widget_bjkc.php';?>
    </div>


    <!-- 作业下载 -->
    <div class='layui-row' style='text-align:center;width:90%;margin:0 auto;' id='res'>

        <div class="layui-row layui-form-item" id="div_down">        </div>

        <div class="layui-row layui-form-item" id="div_yes">
            <div class="layui-col-md12">
            <h3 style="color:green">
                &nbsp; <i class="layui-icon">&#xe650;</i> 已经上传作业：
            </h3>
            <hr>
            <div id="yes" style="line-height:38px;"></div>

        </div>

        <div class="layui-row layui-form-item" id="div_no">
            <div class="layui-col-md12">
            <h3 style="color:red">
                &nbsp; <i class="layui-icon">&#xe69c;</i> 暂未上传作业：
            </h3>
            <!-- <hr> -->
            <div id="no" style="line-height:38px;"></div>
            </div>
        </div>



    </div><!-- row end -->



</div><!--container end-->


<?php include 'inc/teacher_foot.php';?>


<!-- JS脚本开始 -->
<script type="text/javascript">
layui.use(['table', 'form', 'element'], function () {
    var table       = layui.table
        , element   = layui.element
        , form      = layui.form
        , $         = layui.$;
$("#nav_zy").addClass('layui-this'); //设置导航当前选中项的样式

// 机房学生机总数（全局）
let maxPC     = <?=c('maxPC')?>;
// 已选择的班级、课程（全局）
let sel_task  = $('select[name="tasks"]').find("option:selected");
let sel_class = $('select[name="classes"]').find("option:selected");






// 打包下载 开始
form.on('submit(down)',function(){
    let data={};
    data.classes=sel_class.val();
    data.tasks=sel_task.val();
    data.tasksName=sel_task.text();
    let index=layer.msg('正在打包中，请稍候。。。', {icon: 16, time:0, shade:0.3, });
    $.post('/teacher/zipAndDown',data, function (res) {
        console.log(res);
        res==0 ? layer.alert('此课程下，未发现作业文件') : location.assign('/teacher/downZY/'+res);
        layer.close(index);
    });

    return false;
});


// 检查作业函数
function checkZY(sel_class,sel_task){
    let index=layer.msg('检查作业中，请稍候。。。', {icon: 16, time:0, });
    let data={};
    data.classes=sel_class.val();
    data.tasks=sel_task.val();
    $.getJSON('/teacher/checkZY',data,function(res){
        console.log(res);
        if(res=='00'){
            $('#res').hide();
            layer.alert('该班级未注册任何学生！无法查看作业情况！');
        }else{
            $('#res').show();
            $('#yes').empty();
            $('#yes').append('<div style="width:10px;display:inline-block"></div>');
            $('#no').empty();
            $('#no').append('<div style="width:10px;display:inline-block"></div>');

            for (let i in res.yes) {
                $('#yes').append('<span class="layui-btn layui-btn-sm yes" ' +
                'style="width:100px;">'+res.yes[i].site + '' + res.yes[i].name + '</span>');

            }

            // 没有作业可下载的时候隐藏按钮
            if (res.yes){
                $('#yes').append('<br><button class="layui-btn" lay-submit lay-filter="down" style="background:#375B9D;margin-top:10px;width:200px;">点此下载学生作业</button><hr>');
            }else{
                $('#yes').append('<b style="font-size:14pt;">暂无作业可下载</b>');
            }

            for (let i in res.no) {
                if (res.no[i].site < maxPC){
                    console.log(res.no[i].site);
                    $('#no').append('<span class="layui-btn layui-btn-sm no" ' +
                    'style="width:100px;">'+res.no[i].site + '' + res.no[i].name + '</span>');
                }
            }

            layer.close(index);
        }



    });
}

checkZY(sel_class,sel_task);

//选择班级时 刷新
form.on('select()', function(data){
    sel_class = $('select[name="classes"]').find("option:selected");
    sel_task  = $('select[name="tasks"]').find("option:selected");
    checkZY(sel_class,sel_task);
});



});

</script>



<?php include 'inc/teacher_foot.php';?>

